<template>
  <Dialog width="60%" :title="dialogTitle" v-model="dialogVisible" :maxHeight="450">
    <el-scrollbar :style="`height:450px`">
      <el-form ref="formRef" :model="formData" label-width="70px" v-loading="formLoading">
        <el-form-item label="通知标题">
          <el-input
            disabled
            v-model="formData.noticeTitle"
            placeholder="通知标题"
            class="!w-1000px"
          />
        </el-form-item>
        <el-form-item label="通知内容">
          <el-input
            disabled
            autosize
            type="textarea"
            v-model="formData.noticeContent"
            placeholder="通知内容"
            class="!w-1000px"
          />
        </el-form-item>
      </el-form>
    </el-scrollbar>
    <template #footer>
      <el-button @click="dialogVisible = false">关 闭</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import * as DirawingMessageApi from '@/api/technology/dirawingMessage'

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('消息详情') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref({
  ticketId: undefined,
  dictTaskType: undefined,
  noticeTitle: undefined,
  noticeContent: undefined,
  creatorName: undefined,
  updaterName: undefined
})
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (id?: number) => {
  dialogVisible.value = true
  resetForm()
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      formData.value = await DirawingMessageApi.getDirawingMessage(id)
    } finally {
      formLoading.value = false
    }
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    ticketId: undefined,
    dictTaskType: undefined,
    noticeTitle: undefined,
    noticeContent: undefined,
    creatorName: undefined,
    updaterName: undefined
  }
  formRef.value?.resetFields()
}
</script>
